package top.springmvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import top.douma.controllers.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

/**
 * @author Administrator
 * @version 1.0
 * @email lzjg1314@163.com
 * @date 2018/11/1
 */
@Controller
public class HomeController {
  
  @RequestMapping("/home/index")
  public String index(HttpServletRequest req) {
    req.setAttribute("name", "index1");
    return "reg";
  }
  
  @RequestMapping("/home/index2")
  public String index2(Model model) {
    model.addAttribute("name", "index2");
    return "reg";
  }
  
  @RequestMapping("/home/index3")
  public String index3(Map<String, Object> maps) {
    maps.put("name", "index3");
    
    UserInfo user = new UserInfo();
    user.setName("张三", 12);
    user.setPwd("admin");
    user.setSex("女");
    maps.put("age", user);
    return "reg";
  }
  
  @RequestMapping("/home/index4")
  public ModelAndView index4() {
    ModelAndView mv = new ModelAndView("reg");
    mv.getModel().put("name", "index4");
    return mv;
  }
  
  
  @RequestMapping(value = "/action")
  @ResponseBody
  public String action() {
    
    return "{success:true,data:{name:'admin',pwd:'admin'}}";
  }
}
